/**
 * Copyright (c) 2020-2024, huli.com
 * All rights reserved.
 */
package com.xiaohujr.xuexue.spi.factory;


import com.xiaohujr.xuexue.spi.api.Animal;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ServiceLoader;

/**
 * @author Xue Xue (xuexue1@huli.com)
 * @version 1.0
 * @since 2021/1/21
 */
public class AnimalFactory {
    public void invoker() {
        ServiceLoader<Animal> serviceLoader = ServiceLoader.load(Animal.class);
        Iterator<Animal> iterator = serviceLoader.iterator();
        while (iterator.hasNext()){
            Animal animal = iterator.next();
            System.out.println(animal.voice());

        }
    }

    public static void main(String[] args) {
        new AnimalFactory().invoker();
        List<Integer> ansList = new ArrayList<>();
        ansList.toArray(new Integer[]{1});

    }
}
